﻿namespace SimpleCore
{
    public abstract class FsmNode
    {
        public void Enter(object arg = null)
        {
            OnEnter(arg);
            IsEnter = true;
        }

        public void Exit()
        {
            OnExit();
            IsEnter = false;
        }

        public void Update(float interval)
        {
            if (IsEnter)
            {
                OnUpdate(interval);
            }
        }

        /// <summary>
        /// 模版方法
        /// </summary>
        /// <param name="arg"></param>
        protected virtual void OnEnter(object arg = null)
        {
        }

        /// <summary>
        /// 模版方法
        /// </summary>
        protected virtual void OnExit()
        {
        }

        /// <summary>
        /// 模版方法
        /// </summary>
        /// <param name="interval"></param>
        protected virtual void OnUpdate(float interval)
        {
        }

        /// <summary>
        /// 当前节点是否运行
        /// </summary>
        public bool IsEnter { get; private set; }
    }
}